package com.salton123.soulove.sailfish.video.task

import java.util.concurrent.CopyOnWriteArrayList

/**
 * Time:2021/10/22 11:11 上午
 * Author:
 * Description:
 */
object BackgroundTaskManager {
    private val taskList: CopyOnWriteArrayList<IBackgroundTask> = CopyOnWriteArrayList()

    /**
     * 注册任务
     */
    fun register(task: IBackgroundTask) {
        if (!taskList.contains(task)) {
            taskList.add(task)
        }
    }

    /**
     * 反注册任务
     */
    fun unregister(task: IBackgroundTask) {
        taskList.remove(task)
    }

    fun unregisterAll() {
        taskList.clear()
    }

    /**
     * 执行任务
     */
    fun launch() {
        taskList.forEach { it.launch() }
    }
}